<?php
declare(strict_types=1);

namespace app\admin\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Tool extends Model
{
    // 数据转换为驼峰命名
    // protected $convertNameToCamel = true;

    protected $mapping = [
        'tool_name' => 'toolName',
        'tool_intro' => 'toolIntro',
        'tool_logo' => 'toolLogo',
        'tool_href' => 'toolHref',
        'tool_sort' => 'toolSort',
        'create_time' => 'createTime',
        'update_time' => 'updateTime',
        'create_by' => 'createBy',
        'update_by' => 'updateBy'
    ];

    public function toollabel()
    {
        return $this->belongsToMany(Toollabel::class, 'tool_toollabel');
    }

    public function getMappedField($field)
    {
        $mapping = array_search($field, $this->mapping);
        return $mapping ?? $field;
    }
}
